package xyz.zyt123.videowall.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;

public class ConfigUtil {
    public static Properties getConfig() {
        //1.创建Properties集合类
        Properties pro = new Properties();
        //获取src路径下的文件--->ClassLoader类加载器
        //2.加载文件
        File file = new File(System.getProperty("user.dir") + "/config/config.properties");
        if (file.exists()) {
            try {
                pro.load(new FileInputStream(file));
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        if (pro.getProperty("imageFileAddress") == null) {
            pro.setProperty("imageFileAddress", System.getProperty("user.dir")+"\\images");
        }
        if (pro.getProperty("videoFileAddress") == null) {
            pro.setProperty("videoFileAddress", System.getProperty("user.dir")+"\\videos");
        }
        return pro;
    }

    public static void saveConfig(Properties prop) {
        File file = new File(System.getProperty("user.dir") + "/config/config.properties");
        try {
            prop.store(new FileOutputStream(file), null);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static String getImageFileAddress() {
        return getConfig().getProperty("imageFileAddress");
    }
    public static String getVideoFileAddress() {
        return getConfig().getProperty("videoFileAddress");
    }
}
